package com.controller;

import com.pojo.Admin;
import com.service.impl.AdminServiceImpl;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * (Admin)表控制层
 *
 * @author makejava
 * @version 1.0
 * @since 2022-04-08 12:33:27
 */
@RestController
@RequestMapping("/admin")
public class AdminController {
    /**
     * 服务的对象
     */
    @Resource
    private AdminServiceImpl adminServiceImpl;

    /**
     * 查询所有数据
     *
     * @return 返回所有数据
     */
    @RequestMapping(value = "/selectAll")
    public Map<String, Object> selectAll() {
        return this.adminServiceImpl.selectAll();
    }

    /**
     * 查询单条数据()
     *
     * @return 实例对象
     */
    @RequestMapping(value = "/selectByUser")
    public Map<String, Object> selectById(HttpServletRequest request) {
        return this.adminServiceImpl.selectById(request);
    }

    /**
     * 通过一个pojo对象新增单条数据
     *
     * @param admin 一个数据库对应的POJO数据对象
     * @return 返回插入的主键id
     */
    @RequestMapping(value = "/insert")
    public Map<String, Object> insert(@RequestBody Admin admin) {
        return this.adminServiceImpl.insert(admin);
    }

    //修改密码
    @RequestMapping(value = "/UserPassword")
    public Map<String, Object> updatePassword(@RequestParam("password") String password, HttpServletRequest request) {
        return this.adminServiceImpl.updatePassword(password, request);
    }

    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequestMapping(value = "/deleteById")
    public Map<String, Object> deleteById(@RequestParam("id") String id) {
        return this.adminServiceImpl.deleteById(id);
    }

}